//
//  CustomLayout.m
//  ProjectsOne
//
//  Created by iOS开发 on 2018/7/10.
//  Copyright © 2018年 iOS开发. All rights reserved.
//

#import "CustomLayout.h"

@implementation CustomLayout

// 自定义间隙
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
    
    NSMutableArray* attributes = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
    for(int i = 1; i < [attributes count]; ++i) {
        UICollectionViewLayoutAttributes *currentLayoutAttributes = attributes[i];
        UICollectionViewLayoutAttributes *prevLayoutAttributes = attributes[i - 1];
        
        NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
        if(origin + _maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) {
            CGRect frame = currentLayoutAttributes.frame;
            frame.origin.x = origin + _maximumSpacing;
            currentLayoutAttributes.frame = frame;
        }
    }
    return attributes;
}

@end
